import 'dart:convert';
import 'dart:ui';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_aygsh/http/Api.dart';
import 'package:flutter_aygsh/http/HttpUtil.dart';
import '../../base/Constant.dart';
import '../../util/SignUtil.dart';
import '../../liz_mine/set/FillAuthCode.dart';

class MyShopPage extends StatefulWidget {
  String token;
  MyShopPage({Key key, this.token}) : super(key: key);

  @override
  _MyShopPageState createState() => _MyShopPageState();
}

class _MyShopPageState extends State<MyShopPage> {
  String username = "";
  String phone = "";
  String auth_code = "";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getInfo();
  }

  getInfo() async {
    Map map = new Map();
    map['token'] = widget.token;
    map['sign_type'] = createSignType(Api.URL_USER_show_auth);
    Response<String> response =
        await HttpUtil().post(Api.URL_USER_show_auth, data: getSign(map));
    Map userMap = json.decode(response.data);

    if (userMap['code'] == 1 && mounted) {
      setState(() {
        print(userMap);
        username = userMap['data']['username'] == null
            ? ''
            : userMap['data']['username'];
        auth_code = userMap['data']['auth_code'] == null
            ? ''
            : userMap['data']['auth_code'];
        phone =
            userMap['data']['phone'] == null ? '' : userMap['data']['phone'];
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: new AppBar(
          title: new Text(
            "所在店铺",
            style: TextStyle(
                fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                color: Colors.black),
          ),
          elevation: 0,
          backgroundColor: Colors.white,
          brightness: Brightness.light,
          centerTitle: true,
          iconTheme: new IconThemeData(color: Colors.black),
        ),
        body: Container(
            height: kScreenHeight,
            width: ScreenUtil.getInstance().setWidth(750),
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage("images/cover.png"),
                fit: BoxFit.cover,
              ),
            ),
            child: Container(
              alignment: Alignment.topLeft,
              margin: EdgeInsets.all(kMargin60),
              child: Column(
                children: <Widget>[
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: kMargin30),
                    child: Text(
                      'Dear，欢迎光临',
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w300,
                          fontSize:
                              ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: kMargin30),
                    child: Text(
                      '日尚臻选',
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w600,
                          fontSize: ScreenUtil.getInstance()
                              .setSp(BIG_FONT_SIZE * 1.5)),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: kMargin30),
                    child: Text(
                      '我是日尚臻选店主' + username,
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w500,
                          fontSize:
                              ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: kMargin100),
                    child: Text(
                      '店铺邀请码:' + auth_code,
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w500,
                          fontSize:
                              ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
                    ),
                  ),
                  // GestureDetector(
                  //   onTap: () {
                  //     Navigator.of(context)
                  //         .push(new MaterialPageRoute(builder: (context) {
                  //       return new FillAuthCodePage();
                  //     }));
                  //   },
                  //   child: Container(
                  //     alignment: Alignment.topLeft,
                  //     child: Text(
                  //       '切换店铺 >',
                  //       style: TextStyle(
                  //           color: white,
                  //           fontSize: ScreenUtil.getInstance()
                  //               .setSp(NORMAL_FONT_SIZE)),
                  //     ),
                  //   ),
                  // )

                  // Container(child: Text('店铺邀请码'+auth_code==null?'':auth_code),),
                  // Container(child: Text(''),),
                ],
              ),
            )));
  }
}
